//nums，一个跳数 jump，及幸存数量 left。
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let nums = [];
let jump,left;
rl.on("line", (line)=>{
    if(nums.length === 0) {
        nums = line.trim().split(",").map(Number)
    } else if( jump === undefined) {
        jump = Number(line.trim())
    } else{
        left = Number(line.trim())
        console.log(getResult(jump, left, nums))

        // clear
        nums.length = 0
        jump = left = undefined
    }
})

function getResult(jump, left, nums) {
    //若起始时 left > len(nums) 则无需跳数处理过程。
    if(left >= nums.length) {
        return nums.reduce((acc, num)=> acc + num, 0)
    }

    let index = 0
    let remain = nums.length
    let tempIndex = index + jump + 1
    while(remain > left) {
        index = tempIndex % nums.length

        // 敲出
        nums.splice(index, 1);
        remain--
        tempIndex = index + jump
    }
    return nums.reduce((acc, num)=> acc + num, 0)

}